#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
#include "Sender.cpp"

using namespace std;
using namespace cgicc;

string get_request_param(Cgicc& formData,const string &param){
	form_iterator fi=formData.getElement(param);
   	string res;
   	if(!fi->isEmpty() && fi!=(*formData).end()){
   		string temp="";
   		temp=**fi;
   		res=temp;
   	}
   	return res;
}
int main()
{
	Cgicc formData;
	string mes=get_request_param(formData,"message");
	string cipher=get_request_param(formData,"cipher");
	string message=mes+" "+cipher;
	ofstream fout("/home/zhengyl/zyl/socket/Cipher.txt");
	fout<<cipher;
	fout.close();
	Sender sender("127.0.0.1");
	sender.sendMsg("negotiation");

	if(sender.receiveMsg()=="OK"){
		sender.negotiate(message);
	}
	cout<< "Content-type:text/html;charset=utf-8\r\n\r\n"<<endl;
	cout<<message<<endl;
	cout<<sender.receiveMsg()<<endl;
	return 0;
}